﻿using System;
using System.Collections.Generic;
using System.Text;
using GD.ModelContest.Model;
using System.Collections;

namespace GD.ModelContest.DataAccess.Impl.IBatisNet
{
    public class UserSqlMapDao : BaseSqlMapDao, IUserDao
    {
        #region mc_user 对象

        public bool InsertUser(mc_user user)
        {
            object obj = ExecuteInsert("Insertmc_user", user);
            if ((int)obj > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool UpdateUser(mc_user user)
        {
            int ret = ExecuteUpdate("Updatemc_user", user);
            if (ret > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool DeleteUser(int userId)
        {
            int ret = ExecuteDelete("Deletemc_user", userId);
            if (ret > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public mc_user GetUserById(int userId)
        {
            return ExecuteQueryForObject<mc_user>("Selectmc_user", userId);
        }


        public mc_user GetUserLogin(string email, string pwd)
        {
            Hashtable ht = new Hashtable();
            ht["Email"] = email;
            ht["Password"] = pwd;

            return ExecuteQueryForObject<mc_user>("SelectUserLogin", ht);
        }

        public int IsEmailAlreadyExisted(string email)
        {
            Hashtable ht = new Hashtable();
            ht["Email"] = email;

            return ExecuteQueryForObject<int>("GetEmailCount", ht);
        }

        public IList<mc_user> GetUserCollection(string name, string sex, string items, string bodyHeight, string bodyWeight, string bloodType, string city, int pageIndex, int pageSize, ref int count)
        {
            Hashtable ht = new Hashtable();
            ht["Name"] = name;
            ht["Sex"] = sex;
            ht["Items"] = items;
            ht["BodyHeight"] = bodyHeight;
            ht["BodyWeight"] = bodyWeight;
            ht["BloodType"] = bloodType;
            ht["City"] = city;

            IList<mc_user> userCollection = ExecuteQueryForList<mc_user>("SelectUserCollection", ht);
            count = userCollection.Count;
            return ExecuteQueryForList<mc_user>("SelectUserCollection", ht, (pageIndex - 1) * pageSize, pageSize);
        }

        #endregion

        #region mc_photo对象

        public bool InsertPhoto(mc_photo photo)
        {
            object obj = ExecuteInsert("Insertmc_photo", photo);

            if ((int)obj > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool UpdatePhoto(mc_photo photo)
        {
            int ret = ExecuteUpdate("Updatemc_photo", photo);

            if (ret > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool DeletePhoto(int photoId)
        {
            object obj = ExecuteDelete("Deletemc_photo", photoId);

            if ((int)obj > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
		
		public mc_photo GetHeadPhotoByUserId(int userId)
        {
            return ExecuteQueryForObject<mc_photo>("SelectHeadPhoto", userId);
        }

        public IList<mc_photo> GetPhotoCollection(int userId)
        {
            Hashtable ht = new Hashtable();
            ht["UserId"] = userId;

            return ExecuteQueryForList<mc_photo>("SelectPhotoCollectionByUserId", ht);
        }

        #endregion

        #region mc_video对象

        public bool InsertVideo(mc_video video)
        {
            object obj = ExecuteInsert("Insertmc_video", video);

            if ((int)obj > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool UpdateVideo(mc_video video)
        {
            int ret = ExecuteUpdate("Updatemc_video", video);

            if (ret > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool DeleteVideo(int videoId)
        {
            object obj = ExecuteDelete("Deletemc_video", videoId);

            if ((int)obj > 0)
            {
                return true;
            }
            else
            {

                return false;
            }
        }

        public IList<mc_video> GetVideoCollection(int userId)
        {
            Hashtable ht = new Hashtable();
            ht["UserId"] = userId;

            return ExecuteQueryForList<mc_video>("SelectVideoCollectionByUserId", ht);
        }

        #endregion

        #region mc_vote对象

        public bool InsertVote(mc_vote vote)
        {
            object obj = ExecuteInsert("Insertmc_vote", vote);

            if ((int)obj > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool UpdateVote(mc_vote vote)
        {
            int ret = ExecuteUpdate("Updatemc_vote", vote);

            if (ret > 0)
            {
                return true;
            }

            else
            {
                return false;
            }
        }

        public bool DeleteVote(int voteId)
        {
            object obj = ExecuteDelete("Deletemc_vote", voteId);

            if ((int)obj > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public mc_vote GetVoteByUserId(int userId)
        {
            Hashtable ht = new Hashtable();
            ht["UserId"] = userId;

            return ExecuteQueryForObject<mc_vote>("SelectVoteByUserId", ht);
        }

        #endregion

        #region mc_ip对象

        public bool InsertIp(mc_ip ip)
        {
            object obj = ExecuteInsert("Insertmc_ip", ip);

            if ((int)obj > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool UpdateIp(mc_ip ip)
        {
            int ret = ExecuteUpdate("Updatemc_ip", ip);

            if (ret > 0)
            {
                return true;
            }

            else
            {
                return false;
            }
        }

        public bool DeleteIp(int ipId)
        {
            object obj = ExecuteDelete("Deletemc_ip", ipId);

            if ((int)obj > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public mc_ip GetIpByTime(string ip, string startTime, string endTime )
        {
            Hashtable ht = new Hashtable();
            ht["Content"] = ip;
            ht["StartTime"] = startTime;
            ht["EndTime"] = endTime;
            return ExecuteQueryForObject<mc_ip>("SelectIpByTime", ht);
        }

        public int GetIp(string ip)
        {
            Hashtable ht = new Hashtable();
            ht["Content"] = ip;
            return ExecuteQueryForObject<int>("SelectIp", ht);
        }

        #endregion

    }
}
